package org.byqh.dqeai.dto.common;

import java.util.List;
import java.util.Map;

public class PageModel<T> {
    //结果集
    private List<T> list;
    private Map<String, String> columns;

    //查询记录数
    private int totalRecords;

    //第几页
    private int pageNo;

    //每页多少条记录
    private int pageSize;

    //总页数
    public int getTotalPages() {
        return pageSize == 0 ? 0 : (totalRecords + pageSize - 1) / pageSize;
    }

    //首页
    public int getTopPage() {
        return 1;
    }

    //上一页
    public int getPreviousPage() {
        if (pageNo <= 1) {
            return 1;
        }
        return pageNo - 1;
    }

    //下一页
    public int getNextPage() {
        if (pageNo >= getBottomPage()) {
            return getBottomPage();
        }
        return pageNo + 1;
    }

    //尾页
    public int getBottomPage() {
        return getTotalPages();
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Map<String, String> getColumns() {
        return columns;
    }

    public void setColumns(Map<String, String> list) {
        this.columns = list;
    }

    public int getTotalRecords() {
        return totalRecords;
    }

    public void setTotalRecords(int totalRecords) {
        this.totalRecords = totalRecords;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
}
